<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Web Solutions
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2005/08/07 05:20:29 $)
// $RCSfile: functions_visitorbans.php,v $ : $Revision: 1.2 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================


if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

/**
* Adds a new Visitor Ban
*/
function insertBan($ipaddress)
{
	global $dbCore, $_SWIFT;

	$dbCore->shutdownQuery("INSERT INTO `". TABLE_PREFIX ."visitorbans` (`ipaddress`, `dateline`, `staffid`) VALUES ('". $dbCore->escape($ipaddress) ."', '". DATENOW ."', '". intval($_SWIFT["staff"]["staffid"]) ."');");

	return true;
}

/**
* Deletes the given visitor bans from the system
*/
function deleteVisitorBans($visitorbanidlist)
{
	global $dbCore, $_SWIFT;

	if (!_is_array($visitorbanidlist))
	{
		return false;
	}

	$dbCore->query("DELETE FROM `". TABLE_PREFIX ."visitorbans` WHERE `visitorbanid` IN (". buildIN($visitorbanidlist) .");");

	return true;
}

/**
* Updates the given visitor ban
*/
function updateVisitorBan($visitorbanid, $ipaddress)
{
	global $dbCore, $_SWIFT;

	$dbCore->shutdownQuery("UPDATE `". TABLE_PREFIX ."visitorbans` SET `ipaddress` = '". $dbCore->escape($ipaddress) ."', `dateline` = '". DATENOW ."', `staffid` = '". intval($_SWIFT["staff"]["staffid"]) ."' WHERE `visitorbanid` = '". intval($visitorbanid) ."';");

	return true;
}

function isValidIP($ip) {
	$valid = TRUE;

	if(preg_match("/^((127)|(192)|(10).*)$/", "$ip")) {
		return FALSE;
	}

	$ip = explode(".", $ip);
	if(count($ip)!=4) {
		return FALSE;
	}
	
	foreach($ip as $block) {
		if(!is_numeric($block) || $block>255 || $block<1) {
			$valid = FALSE;
		}
	}
	
	return $valid;
}
?>